define(['zepto', 'utils', 'JST', 'sui', 'submitForm'], function($, utils, JST){
  return {
    init: function(data) {
      this.courseRoundId = data.courseRoundId;
      this.initPicker();
      this.initSubmit();
     
    },
    
    
    initPicker: function() {
      var that = this;
      
      $('[data-name="direction"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'LEFT', 'RIGHT'],
            displayValues: ['正常', '内扣', '外扣']
          },
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value)
          return displayValue
        },
      });
      
      $('[data-name="parallel"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['true', 'false'],
            displayValues: ['是', '否']
          },
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value)
          return displayValue
        },
      });
      
      $('[data-name="arthrosis"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['GOOD', 'LACKING', 'AWFUL'],
            displayValues: ['良好', '不足', '严重受限']
          },
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value)
          return displayValue
        },
      });
      
      $('[data-name="standingPosture1"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'LEFT', 'RIGHT'],
            displayValues: ['中立位', '前引', '后仰']
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value);
          console.log(picker)
          return displayValue
        }
      })
      
      $('[data-name="standingPosture2"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'UNNORMAL'],
            displayValues: ['中立位', '圆肩'],
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value);
          return displayValue
        }
      })
      
      $('[data-name="standingPosture3"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'LEFT', 'RIGHT'],
            displayValues: ['中立位', '前倾', '后倾'],
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value);
          return displayValue
        }
      })
      
      $('[data-name="standingPosture4"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'LEFT', 'RIGHT'],
            displayValues: ['中立位', '膝外翻', '膝内翻'],
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value);
          return displayValue
        }
      })
      
      $('[data-name="backPosture1"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['NORMAL', 'UNNORMAL'],
              displayValues: ['中立位', '侧倾']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value);
            return displayValue
          },
      })
      
      $('[data-name="backPosture2"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['NORMAL', 'UNNORMAL'],
              displayValues: ['中立位', '扭转']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value);
            return displayValue
          },
      })
      
      $('[data-name="backPosture3"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'LEFT', 'RIGHT'],
            displayValues: ['中立位', '左高', '右高']
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value);
          return displayValue
        }
      })
      
      $('[data-name="backPosture4"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
        cssClass: 'evaluation-picker',
        onOpen: function(picker) {
          that.currentPicker = $(this.input)
        },
        cols: [
          {
            textAlign: 'center',
            values: ['NORMAL', 'UNNORMAL'],
            displayValues: ['中立位', '超伸']
          }
        ],
        formatValue: function (picker, value, displayValue){
          $(this.input).parent().find('input[type="hidden"]').val(value);
          return displayValue
        }
      })
      
      $('[data-name="backPosture5"]').picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-left cancel-picker">取消</button>\
          <button class="button button-link pull-right close-picker">确定</button>\
          </header>',
          cssClass: 'evaluation-picker',
          onOpen: function(picker) {
            that.currentPicker = $(this.input)
          },
          cols: [
            {
              textAlign: 'center',
              values: ['NORMAL', 'UNNORMAL'],
              displayValues: ['正常', '扁平足']
            }
          ],
          formatValue: function (picker, value, displayValue){
            $(this.input).parent().find('input[type="hidden"]').val(value);
            return displayValue
          },
      })
      
      $(document).on("click", ".cancel-picker", function() {
        
        $.closeModal(".picker-modal.modal-in")
        var currentElement = $(that.currentPicker)
        console.log(currentElement.data("val"))
        var val = currentElement.data("val") ? currentElement.data("val") : ""
        var defaultVal = currentElement.data("default-val") ? currentElement.data("default-val") : ""
        
        currentElement.parent().find('input[type="hidden"]').val(val)
        currentElement.val(defaultVal)
      })
      
    },
    
    initSubmit: function() {
      $("form").submitform({
        successUrl: $(".fs-header-small a").attr('href')
      })
    }
  }
})